from glob import glob
import os
import random
import os
from os import listdir, getcwd
from os.path import join
import shutil
import cv2
import numpy as np
import argparse



def preprocess():
    dirs = os.listdir('/home/eason/Downloads/Training_Batch1/media/nas/01_Datasets/CT/LITS/mask/tumor_label')
    for file in dirs:
        filename = '/home/eason/Downloads/Training_Batch1/media/nas/01_Datasets/CT/LITS/mask/tumor_label/' + file
        name = '/home/eason/Downloads/Training_Batch1/media/nas/01_Datasets/CT/LITS/mask/new/' + file
        img = cv2.imread(filename)
        try:
            img.shape
        except:
            print('fail to read')
            continue
        img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        for row in range(img.shape[0]):            #遍历高
            for col in range(img.shape[1]):         #遍历宽
                if(img[row, col]!=0):img[row, col]=1     
        cv2.imwrite(name, img)
if __name__ == "__main__":
    preprocess()

